package com.itheima.demo06;

import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.*;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/15 11:32
 */
public class Demo_003 {
    public static void main(String[] args) throws InterruptedException {
        //创建一个map集合 ;
        ConcurrentMap<String, String> map = new ConcurrentHashMap<>();
        ArrayList<String> list = new ArrayList<>();
        list.add("C:\\Users\\97622\\Desktop\\ROBIN\\day16.md");
        list.add("C:\\Users\\97622\\Desktop\\ROBIN\\day18.md");
        list.add("C:\\Users\\97622\\Desktop\\ROBIN\\day15.md");
        list.add("C:\\Users\\97622\\Desktop\\ROBIN\\day17.md");
        list.add("C:\\Users\\97622\\Desktop\\ROBIN\\day19.md");
        ThreadPoolExecutor tpe = new ThreadPoolExecutor(1,
                1,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(list.size()),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        CountDownLatch cdl = new CountDownLatch(list.size());
        for (int i = 0; i < list.size(); i++) {
            MyRunnable03 mr = new MyRunnable03(list.get(i), cdl, map);
            tpe.submit(mr);
        }
        cdl.await();
        tpe.shutdown();
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println("文件名:" + key + ";时间:" + value);

        }
        System.out.println("文件复制完成!");
    }
}
